package graph.impl;

import edu.princeton.cs.introcs.In;
import edu.princeton.cs.introcs.StdOut;
import graph.design.GenericGraph;

public class StringGraph extends GenericGraph<String> {

	public StringGraph(In in){
		super();
		String line = in.readLine();
		
		while(line != null) {			
			if(line != null && line.length() > 0){
				String[] items = line.split(" ");
				String vertex = items[0].trim();
				this.addVertex(vertex);
				
				if(items.length > 1){
					String edge = items[1].trim();
					this.addEdgeTo(vertex, edge);
				}
			}
			line = in.readLine();
		}		
	}
	
	public static void main(String[] args) {
		In in = new In(args[0]);
		StringGraph stringGraph = new StringGraph(in);
		StdOut.println(stringGraph.toString());
		StdOut.println("vertex count = " + stringGraph.vertexCount);
	}
}
